SERVO MOTOR INTERFACING WITH RASPBERRY Pi
In this project, we will learn how to control the position of a servo motor using Raspberry Pi. A servo motor is a rotary motor that allows you to control the motor in specific angular position, velocity, and acceleration. Servo motor works on PWM (pulse width modulation) principle and basically made up of DC motor which is controlled by a variable resistor and gears.
Synopsis:

In this project, we will learn how to control the position of a servo motor using Raspberry Pi. A servo motor is a rotary motor that allows you to control the motor in specific angular position, velocity, and acceleration. Servo motor works on PWM (pulse width modulation) principle and basically made up of DC motor which is controlled by a variable resistor and gears.

Description


Servo Motor

There are some types of applications where the rotation of the motor is required at a specific angle for a given electric pulse to make this possible servo motor came in existence. Servo motor rotates as much as we require and stop and waits for the next signal to take further action. A typical servo motor consists of three parts -Power, control, and ground.

There are different types of servo motors they are.

DC servo motor:

DC servo motor is the same as DC motor but differs in construction, design, and operation. This type of motor is designed with long rotor length and have a small diameter. There are different types of Dc servo motors they are. a. Series motors b. Split series motor c. Shunt control motor d. Permanent magnet shunt motor

AC servo motor:

Ac servo motors are AC motors in which encoders are used with controllers to provide close-loop controller and feedbacks. These motors are positioned at high accuracy. They are classified into two types a. 2-phase servo motor b. 3-phase servo motor

Brushless DC servo motor:

They are commonly known as synchronous motors that have DC electricity with switching power supply. Hence provides AC current to drive each phase of the motor with a closed-loop controller.

Positional rotation servo motor:

These are the most common types and important servo motor. The shaft output rotates about 180degress. It includes a physical stop gear mechanism to stop turning outside that limits to guard the rotation.

Continuous rotation servo motor:

These are related to common positional rotation servo motor but can go in any direction. The range of position commands the servo motor to rotate a clockwise and anti-clockwise direction as preferred.

Linear servo motor:

These motors are similar to positional rotation servo motor by extra gears that are used to alter the output to move backward and font.

Raspberry Pi:

Raspberry Pi is a low cost, small size computer that plugs into a computer monitor, and uses a keyboard and mouse. It is capable device that enables us to explore computing and to learn how to program in languages like scratch and python. It is capable of doing what we expect a computer to do. It has many interfaces like HDMI, multiple USB, Ethernet, onboard Wi-Fi and Bluetooth, GPIOs, USB powered etc. also supports to LINUX, Python to make easy to build applications. Raspberry is available in different versions the latest version of Raspberry Pi is Pi3+ Model and the Updated version is Pi4 model. In Raspberry Pi 3B+ Model this model is having 64-bit quad core (processor) running at 1.4GHz, dual band 2.4GHz, 5GHz wireless LAN, Bluetooth 4.2/BLE, faster Ethernet, and PoE (power on Ethernet) capability with separate PoE HAT. Raspberry Pi3 Mode B+ maintains the same footprint as raspberry Pi2 and Raspberry Pi3 Model B.


Pin configuration:

1. Vin: Two 5v pins and two 3v3 pins used for providing power supply, where processor works on 3.3v.

2. Ground: Having 8 ground Pins which are un-configurable.

3. GPIO: There are 26 input-output pins which will be used as input or output based on programming.

4. PWM: In software PWM are available for all pins but in hardware PWM is available for GPIO12, GPIO13, GPIO18, and GPIO19.

5. 2 SPI bus: These pins are used for SPI communication the pins which are used for SPI is MISO, MOSI, SCLK, CE0, and CE1

6. I2C: These pins are used for I2C communication in which DATA and CLOCK pins are used for sending data to and from the SDA connection, with the speed controlled with SCL pin and ID-SE, ID-SC are reserved for ID EEPROM.

7. TX and RX: this pins are used for UART communication.

Schematic


Code:

import RPi.GPIO as GPIO
import time

servoPIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(servoPIN, GPIO.OUT)

p = GPIO.PWM(servoPIN, 50) # GPIO 17 for PWM with 50Hz
p.start(2.5) # Initialization
try:
  while True:
    p.ChangeDutyCycle(5)
    time.sleep(0.5)
    p.ChangeDutyCycle(7.5)
    time.sleep(0.5)
    p.ChangeDutyCycle(10)
    time.sleep(0.5)
    p.ChangeDutyCycle(12.5)
    time.sleep(0.5)
    p.ChangeDutyCycle(10)
    time.sleep(0.5)
    p.ChangeDutyCycle(7.5)
    time.sleep(0.5)
    p.ChangeDutyCycle(5)
    time.sleep(0.5)
    p.ChangeDutyCycle(2.5)
    time.sleep(0.5)
except KeyboardInterrupt:
  p.stop()
  GPIO.cleanup()

Error message here!

Show Error message here!


Forgot your password?

Error message here!

Send OTP

Error message here!

Show Error message here!


Lost your password? Please enter your email address. You will receive a password you Need.

Send Error message here!


Back to log-in

Close